"""登录页面"""
from common.base import Base
from config import host_url
from selenium.webdriver.common.by import By


class LoginPage(Base):
    url = "/User/login.html"

    #账号登录中的元素定位
    account_loactot = (By.NAME,"account") #账号
    pwd_loactot = (By.NAME,"pass") #密码
    btn_loactot = (By.XPATH,"//div[@class='padding-cont pt-login']/a[@class='btn-btn']") # 登录按钮

    #错误提示的元素定位
    account_error_loactot = (By.XPATH,"//input[@name='account']/following-sibling::p") #账号输入框下的错误提示元素定位
    pwd_error_loactot = (By.XPATH,"//input[@name='pass']/following-sibling::p") #密码输入框下的错误提示元素定位


    def get_login_url(self):
        """获取登录页面的地址"""
        login_url = host_url+self.url
        self.driver.get(login_url)

    def login(self,username,pwd):
        """登录操作"""
        self.get_login_url()
        self.driver.refresh()
        self.input(locator=self.account_loactot,data=username)
        self.input(locator=self.pwd_loactot,data=pwd)
        self.click(self.btn_loactot)


    def get_account_error_msg(self):
        """获取账号输入框下的错误信息"""
        error_msg = self.get_element(self.account_error_loactot)
        return error_msg.text

    def get_pwd_error_msg(self):
        """获取密码输入框下的错误信息"""
        error_msg = self.get_element(self.pwd_error_loactot)
        return error_msg.text







